fix(web): preserve node progress on Play resume + drill-back#96
Conversation
Two related bugs that share the same root: cumulative state (per- node progress, create/destroy) wasn't re-derived from the step index on key transitions. 1. Click a node mid-pause → that node's outgoing-step counter increments (handleNodeClick → setNodeStep). Press Play → autoplay resumes from where it was, but the node's progress bar stays ahead of where autoplay would actually be. 2. Drill into a sub-flow → click Back → parent flow's progress bars reset to zero. FlowCanvasInner's key includes node ids, so the parent component remounts fresh, dropping nodeProgressRef even though stepIndexRef was correctly seeded from resumeFromStep. Both fixed by extracting the inline cumulative-replay logic from goToStep into `applyEffectsThroughStep(idx)` and calling it from two new sites: - Mount-time effect: when stepIndexRef.current >= 0 on first render (i.e., startFromStep was set), replay 0..stepIndexRef and push into state so the parent flow's progress survives drill-back. - Play-resume branch in the [playing] effect: replay 0..stepIndexRef before re-entering the phase, so any manual node clicks during the pause get snapped back to autoplay-expected state. goToStep also refactored to use the same helper (no behavior change).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR refactors ChangesCumulative Step Effects Replay
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
* chore: bump @openhop/web 0.1.0-beta.1 → 0.1.0-beta.2 and openhop CLI 0.1.0-beta.3 → 0.1.0-beta.4 Web bumps for the canvas/UI work since beta.1: - pause behavior fix + label overflow + back-edge corridor (#90) - carrot click opens inspect with multi-target highlight + on-canvas playback controls (#93) - bookmark-style toggle tabs for sidebar + inspector (#95) - preserve node progress on Play resume + drill-back (#96) - shrink sprite SVGs by 46% (3.7MB → 2.0MB) (#97) CLI bumps to ship the new web bundle (its only change is the pinned @openhop/web dependency moving to 0.1.0-beta.2). @openhop/server stays at 0.1.0-beta.1 — no changes since last publish. * fix(cli): bump hardcoded --version to 0.1.0-beta.4 Test contract.test.ts asserts `openhop --version` matches the package.json version. The bump in 9b373aa missed the duplicate hardcoded string in src/index.ts:53. Sync them up so CI passes.
Two related bugs, same root: cumulative state (per-node progress + create/destroy) wasn't re-derived from the step index on key transitions.
What's fixed
1. Click-then-Play kept stale progress
Clicking a node fires its next outgoing step manually (good). But that increment lives in
nodeProgressRef, which autoplay also uses. So:2. Drill-down → Back wiped parent's progress
<FlowCanvasInner>is keyed on the node-id list, so drilling into a sub-flow remounts the inner component on return — freshnodeProgressRef = new Map(). Even thoughresumeFromStepwas correctly seeded intostepIndexRef, the per-node bars all snapped to zero.Implementation
goToStepinto a sharedapplyEffectsThroughStep(idx)helper.useEffect: ifstepIndexRef.current >= 0on first render (i.e.,startFromStepwas set), replay0..stepIndexRefand push into state. Fixes Compose roads from a single line #2.[playing]effect now also replays before re-entering the phase. Fixes fix: tighten road endpoints against node art #1.goToSteprefactored to use the same helper — no behavior change.Verification
npm run typecheck— cleannpm test— 40/40npm run format:check— clean🤖 Generated with Claude Code
Summary by CodeRabbit